/**
 * 
 */
package com.whu.waterworks.service;

import java.text.SimpleDateFormat;
import java.util.List;

import com.whu.waterworks.dao.QualityNonNormDao;
import com.whu.waterworks.model.QualityNonNormol;

/**
 * @author： Joymin
 * @date：2016-4-3 下午5:22:41
 * 说明: 
 */
public class QualityNonNormService {
	private boolean flag=false;	
	private QualityNonNormDao  qualityNonNormDao;
	
	public String addQualityNonNormol(QualityNonNormol norm,String type){
		//录入限值
				String message="";
				if(type.equals("1")){
					System.out.println("type=1");
					QualityNonNormol temp=qualityNonNormDao.getLimitedQualityNonNormol();
					if(null!=temp){
						flag=qualityNonNormDao.updateQualityNonNormol(norm);
					}
					else{				
						//norm.setwaterplantId("000000000000");
						norm.setType("1");
						flag=qualityNonNormDao.saveQualityNonNormol(norm);
					}			
				}
				//录入检测数据
				else{
					System.out.println("type=0");
					norm.setType("0");
					SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//设置日期格式			
					System.out.println(norm.getTime());
					if(null==norm.getId()){
						flag=qualityNonNormDao.saveQualityNonNormol(norm);
					}
					else{
						flag=qualityNonNormDao.updateQualityNonNormol(norm);
					}			
				}
				if(flag){
					message="提交成功！";
				}
				else{
					message="提交失败，请稍后！";
				}
				return message;
	}
	
	
	public QualityNonNormol getDataOfLimitNonNorm(){
		return qualityNonNormDao.getLimitedQualityNonNormol();
	}
	
	public String delQualityNonNormol(QualityNonNormol norm){
		String message="";
		flag=qualityNonNormDao.delQualityNonNormol(norm);
		if(flag){
			message="删除成功！";
		}
		else{
			message="删除失败，请稍后！";
		}
		return message;
	}
	
	public QualityNonNormol getQualityNonNormById(String id){
		return qualityNonNormDao.getQualityNonNormolById(id);
	}	

	public QualityNonNormDao getQualityNonNormDao() {
		return qualityNonNormDao;
	}

	public void setQualityNonNormDao(QualityNonNormDao qualityNonNormDao) {
		this.qualityNonNormDao = qualityNonNormDao;
	}

	//zhoululu
		public List<QualityNonNormol> getQualityNonNormols(String code,String startTime,String endTime){
			return qualityNonNormDao.getQualityNonNormols(code, startTime, endTime);	
		}
	
	
}
